<template>
  <div class="cbd-header-wrap" data-v-741978ef>
    <div
      data-spm="hdn"
      data-spm-stop="init"
      class="header-box"
      style="background-color:#d8242e;"
      data-v-741978ef
    >
      <img
        :src="require('@/assets/img/icon/bg_sf.png')"
        style="display:block;position:absolute;height:100%;right:0;"
        data-v-741978ef
      />
      <a
        href="#"
        data-spm-acode="3002"
        data-spm-type="content"
        class="header-logo"
        data-v-741978ef
        data-spm-data="1"
      >
        <img :src="require('@/assets/img/icon/app_logo.png')" data-v-741978ef />
      </a>
      <a
        href="#"
        data-spm-acode="3001"
        data-spm-type="content"
        class="header-search"
        style="background-color:#ffe5b6;color:#e1a235;"
        data-v-741978ef
        data-spm-data="2"
      >
        <span class="header-qbtn" data-v-741978ef>
          <i class="i-search-news"></i>
        </span>
        <section class="header-query" data-v-741978ef>庆余年第二季预告</section>
        <div
          class="search-shade"
          style="background-image:linear-gradient(90deg, rgba(255,229,182, 0) 0%, rgba(255,229,182, 0.94) 74%, rgba(255,229,182, 1) 100%);"
          data-v-741978ef
        ></div>
      </a>
      <a
        href="#" @click="toMoreLinks"
        data-spm-type="content"
        class="header-sites"
        style="background-color:rgba(216,36,46, 1);border:1px solid #f25a3d;color:#fecc9f;"
        data-v-741978ef
        data-spm-data="3"
      >名站</a>
      <span class="header-avatar" data-v-741978ef>
        <a
          @click="toRegister"
          href="#"
          data-spm-acode="3415"
          class="header-avatar-wrapper"
          data-v-741978ef
          data-spm-data="4"
        >
          <img :src="require('@/assets/img/icon/ic_home.png')" />
        </a>
      </span>
    </div>
  </div>
</template>

<script>
import "../../assets/css/appCss/appHeader.css";

export default {
  data() {
    return {};
  },
  methods: {
    toMoreLinks(){
      this.$router.push({name:'moreLinks'})
    },
    async toRegister() {
      let token = localStorage.getItem("sohuToken");

      if (token) {
        //有token：登陆了，验证token
        let { data } = await this.$axios.get(
          "http://localhost:9394/users/verify",
          {
            params: {
              token
            }
          }
        );

        if (data.type) {
          //成功
          this.$router.push({ name: "userCenter" });
        } else {
          //失败
          localStorage.removeItem("sohuToken");
          localStorage.removeItem("sohuUsername");
          this.$router.push({ name: "login" });
        }
      } else {
        this.$router.push({ name: "login" });
      }
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {}
};
</script>

<style scoped>
</style>